//
//  LoginView.m
//  U_card
//
//  Created by 陈如意 on 2018/3/19.
//  Copyright © 2018年 陈如意. All rights reserved.
//

#import "LoginView.h"

@interface LoginView()

// 登陆注册背景view
@property (nonatomic, strong) UIView * bgView;

@property (nonatomic, strong) UIImageView * logoImage;
@property (nonatomic, strong) UIImageView * bottomImage;


// 登陆button
@property (nonatomic, strong) UIButton * signBtn;

// 忘记密码button
@property (nonatomic, strong) UIButton * forgetBtn;

// 注册button
@property (nonatomic, strong) UIButton * registerBtn;

// 线
@property (nonatomic, strong) UIView * line1;
@property (nonatomic, strong) UIView * line2;

@property (nonatomic, strong) UIView * line3;

@end

@implementation LoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initUI];
    }
    return self;
}

- (void)initUI{
    
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];

    [self.bgView.layer addSublayer:[UIColor setColor:self.bgView fromColor:@"#000612" toColor:@"#474E66"]];    
    [self addSubview:self.bgView];
    
    self.logoImage = [UIImageView new];
    self.logoImage.image = [UIImage imageNamed:@"LOGO"];
    [self.bgView addSubview:self.logoImage];
    
    [self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(__I6Height(80));
        make.centerX.equalTo(self.bgView);
    }];
    
    self.accountField = [UITextField new];
    self.accountField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.accountField.keyboardType = UIKeyboardTypePhonePad;
    self.accountField.textAlignment = NSTextAlignmentCenter;
    self.accountField.placeholder = @"请输入手机号";
    self.accountField.text = [Tool objectForKey:@"ID"];
    [self.accountField setValue:[UIColor colorWithHexString:@"#999999"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.accountField setValue:KSHSystemFont(14) forKeyPath:@"_placeholderLabel.font"];
    self.accountField.font = KSHSystemFont(14);
    self.accountField.textColor = [UIColor whiteColor];
    [self.bgView addSubview:self.accountField];
    
    [self.accountField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(15);
        make.top.equalTo(self.logoImage.mas_bottom).offset(__I6Height(65));
        make.centerX.equalTo(self.bgView);
        make.left.equalTo(self.bgView).offset(__I6Width(88));
        make.right.equalTo(self.bgView).offset(-__I6Width(88));
    }];

    self.line1 = [UIView new];
    self.line1.backgroundColor = [UIColor colorWithHexString:@"#D2D2D2"];
    [self.bgView addSubview:self.line1];
    
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.accountField.mas_bottom).offset(5);
        make.left.right.equalTo(self.accountField);
        make.height.mas_offset(.5);
    }];
    
    self.passwordField = [UITextField new];
    self.passwordField.secureTextEntry = YES;
    self.passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.passwordField.textAlignment = NSTextAlignmentCenter;
    self.passwordField.placeholder = @"请输入密码";
    [self.passwordField setValue:[UIColor colorWithHexString:@"#999999"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.passwordField setValue:KSHSystemFont(14) forKeyPath:@"_placeholderLabel.font"];
    self.passwordField.font = KSHSystemFont(14);
    [self.bgView addSubview:self.passwordField];
    
    [self.passwordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.accountField);
        make.top.equalTo(self.line1.mas_bottom).offset(__I6Height(32));
    }];
    
    self.line2 = [UIView new];
    self.line2.backgroundColor = [UIColor colorWithHexString:@"D2D2D2"];
    [self.bgView addSubview:self.line2];
    
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.line1);
        make.top.equalTo(self.passwordField.mas_bottom).offset(5);
    }];
    
    self.signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.signBtn setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateNormal];
    [self.signBtn setTitle:@"登录" forState:UIControlStateNormal];
    self.signBtn.titleLabel.font = KSHSystemFont(16);
    [self.signBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
    [self.signBtn addTarget:self action:@selector(signBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.signBtn];
    
    [self.signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line2.mas_bottom).offset(__I6Height(32));
        make.left.right.equalTo(self.line2);
    }];
    
    self.line3 = [UIView new];
    self.line3.backgroundColor = [UIColor colorWithHexString:@"#E0E0E0"];
    [self.bgView addSubview:self.line3];
    
    [self.line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.signBtn.mas_bottom).offset(__I6Height(30));
        make.centerX.equalTo(self.bgView);
        make.width.mas_offset(.5);
        make.height.mas_offset(__I6Height(16));
    }];
    
    self.forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.forgetBtn setTitle:@"忘记密码？" forState:UIControlStateNormal];
    self.forgetBtn.titleLabel.font = KSystemFont(14);
    self.forgetBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.forgetBtn setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    [self.forgetBtn addTarget:self action:@selector(forgetAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.forgetBtn];

    [self.forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.line3.mas_left).offset(-__I6Width(24));
        make.height.mas_offset(25);
        make.centerY.equalTo(self.line3);
    }];
    
    self.registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.registerBtn setTitle:@"注册账户" forState:UIControlStateNormal];
    self.registerBtn.titleLabel.font = KSystemFont(14);
    self.registerBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.registerBtn setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    [self.registerBtn addTarget:self action:@selector(registerAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.registerBtn];
    
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.line3.mas_right).offset(__I6Width(24));
        make.height.mas_offset(25);
        make.centerY.equalTo(self.line3);
    }];
 
    self.bottomImage = [UIImageView new];
    self.bottomImage.image = [UIImage imageNamed:@"bottom_bg"];
    [self.bgView addSubview:self.bottomImage];
    
    [self.bottomImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line3.mas_bottom).offset(__I6Height(37));
        make.centerX.equalTo(self.bgView);
    }];
}

#pragma mark - 点击注册事件
- (void)registerAction{
    
    NSNotification * notification = [NSNotification notificationWithName:@"register" object:nil];
    
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    
}

#pragma mark - 点击登录事件
- (void)signBtnAction{
    NSNotification * notification = [NSNotification notificationWithName:@"sign" object:nil];
    
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}
#pragma mark - 点击忘记事件
- (void)forgetAction{
    NSNotification * notification = [NSNotification notificationWithName:@"forget" object:nil];
    
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}

@end
